package com.ruoyi.product.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.Result;
import com.ruoyi.product.request.MallProductInfoRequest;
import com.ruoyi.product.response.MallProductResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.product.domain.MallProductInfo;
import com.ruoyi.product.service.IMallProductInfoService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 商品信息Controller
 * 
 * @author ruoyi
 * @date 2025-07-28
 */
@RestController
@RequestMapping("/info")
public class MallProductInfoController extends BaseController
{
    @Autowired
    private IMallProductInfoService mallProductInfoService;

    /**
     * 查询商品信息列表
     */
    @RequiresPermissions("product:info:list")
    @GetMapping("/list")
    public Result<TableDataInfo> list(MallProductInfo mallProductInfo)
    {
        startPage();
        List<MallProductResponse> list = mallProductInfoService.selectMallProductInfoList(mallProductInfo);
        return getDataTable(list);
    }

    /**
     * 导出商品信息列表
     */
    @RequiresPermissions("product:info:export")
    @Log(title = "商品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallProductInfo mallProductInfo)
    {
        List<MallProductResponse> list = mallProductInfoService.selectMallProductInfoList(mallProductInfo);
        ExcelUtil<MallProductResponse> util = new ExcelUtil<MallProductResponse>(MallProductResponse.class);
        util.exportExcel(response, list, "商品信息数据");
    }

    /**
     * 获取商品信息详细信息
     */
    @RequiresPermissions("product:info:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") String id)
    {
        return success(mallProductInfoService.selectMallProductInfoById(id));
    }

    /**
     * 获取商品信息详细信息
     */
    @RequiresPermissions("product:info:query")
    @GetMapping(value = "/findByName/{productName}")
    public Result findByName(@PathVariable("productName") String productName)
    {
        MallProductInfo mallProductInfo = new MallProductInfo();
        mallProductInfo.setName(productName);
        return success(mallProductInfoService.selectMallProductInfoList(mallProductInfo));
    }

    /**
     * 新增商品信息
     */
    @RequiresPermissions("product:info:add")
    @Log(title = "商品信息", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody MallProductInfoRequest mallProductInfoRequest)
    {
        return toAjax(mallProductInfoService.insertMallProductInfo(mallProductInfoRequest));
    }

    /**
     * 修改商品信息
     */
    @RequiresPermissions("product:info:edit")
    @Log(title = "商品信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody MallProductInfoRequest mallProductInfoRequest)
    {
        return toAjax(mallProductInfoService.updateMallProductInfo(mallProductInfoRequest));
    }

    /**
     * 删除商品信息
     */
    @RequiresPermissions("product:info:remove")
    @Log(title = "商品信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable String[] ids)
    {
        return toAjax(mallProductInfoService.deleteMallProductInfoByIds(ids));
    }
}
